<template>
	<view class="change-alphabet">
		<view class="list">
			<view class="item" hover-class="hover" v-for="(item,index) in city" @click="click(item)" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd" :key="index">
				{{item.initial}}
			</view>
		</view>
	</view>
</template>

<script>
	var timer = null
	export default {
		props:['city'],
		data() {
			return {
				touch:false
			};
		},
		methods:{
			click(item){
				this.$emit('change',item.initial)
			},
			touchStart(){
				this.touch = true
			},
			touchEnd(){
				this.touch = false
			},
			touchMove(e){
				clearTimeout(timer)
				timer = setTimeout(()=>{
					if(this.touch){
						const touchY = e.changedTouches[0].clientY-150
						const index = Math.floor(touchY/18)
						if( 0 <= index && index <= this.city.length-1){
							this.$emit('change',this.city[index].initial)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.change-alphabet {
		position: fixed;
		right: 0;
		top: 150px;
		z-index: 20;
		color: #ffffff;
		.list {
			width: 30px;
			.item{
				text-align: center;
				line-height: 18px;
				font-size: 12px;
			}
			.hover{
				font-size: 15px;
			}
		}
	}
	
</style>
